﻿using Engine;
using Game;


public class XFWidget : CanvasWidget
{
    public ComponentPlayer m_componentPlayer;

    public SubsystemNK m_subsystemHL;

    public ComponentMiner componentMiner;

    public ButtonWidget m_XFButton;

    public ButtonWidget m_XF1Button;

    public ButtonWidget m_XF2Button;

    public ButtonWidget m_XF3Button;

    public ButtonWidget m_XF4Button;

    public ButtonWidget m_XF5Button;

    public GridPanelWidget m_inventoryGrid;

    public IInventory m_inventory;

    public SubsystemGameInfo m_subsystemGameInfo;
    public SubsystemTime subsystemTime;
    public NK9 nk;
    //下面是新人物状态按钮系统
    public XFWidget(ComponentPlayer componentPlayer, SubsystemNK subsystemHL)
    {
        m_componentPlayer = componentPlayer;
        m_subsystemHL = subsystemHL;


        m_inventory = m_componentPlayer.ComponentMiner.Inventory;
        //XElement node = ContentManager.Get<XElement>("Widgets/xf");
        //LoadContents(this, node);
       // m_XFButton = Children.Find<ButtonWidget>("XF");
        //m_XF1Button = Children.Find<ButtonWidget>("XF1");
        //m_XF2Button = Children.Find<ButtonWidget>("XF2");
        //m_XF3Button = Children.Find<ButtonWidget>("XF3");
       // m_XF4Button = Children.Find<ButtonWidget>("XF4");
       // m_XF5Button = Children.Find<ButtonWidget>("XF5");
       // m_inventoryGrid = Children.Find<GridPanelWidget>("InventoryGrid");
    }

    public override void MeasureOverride(Vector2 parentAvailableSize)
    {
        int max = (m_inventory is ComponentCreativeInventory) ? 10 : 7;
        m_inventory.VisibleSlotsCount = MathUtils.Clamp((int)((parentAvailableSize.X - 320f - 25f) / 72f), 7, max);
        if (m_inventory.VisibleSlotsCount != m_inventoryGrid.Children.Count)
        {
            m_inventoryGrid.Children.Clear();
            m_inventoryGrid.RowsCount = 1;
            m_inventoryGrid.ColumnsCount = m_inventory.VisibleSlotsCount;
            for (int i = 0; i < m_inventoryGrid.ColumnsCount; i++)
            {
                var inventorySlotWidget = new InventorySlotWidget();
                inventorySlotWidget.AssignInventorySlot(m_inventory, i);
                inventorySlotWidget.Size = new Vector2(50f, 50f);
                inventorySlotWidget.BevelColor = new Color(181, 172, 154) * 0.6f;
                inventorySlotWidget.CenterColor = new Color(181, 172, 154) * 0.33f;
                m_inventoryGrid.Children.Add(inventorySlotWidget);
                m_inventoryGrid.SetWidgetCell(inventorySlotWidget, new Point2(i, 0));
            }
        }
        base.MeasureOverride(parentAvailableSize);
    }

    public override void Update()
    {
        NK9 hL = m_componentPlayer.Entity.FindComponent<NK9>();
        float JC = m_subsystemHL.JC * 100;
        float JianJC = m_subsystemHL.JianJC * 100;
        float DD = m_componentPlayer.PlayerData.Level / 10f * 100;
        float XF = hL.XF * 100;
        bool flag5 = hL.flag5;
        int activeBlockValue = m_componentPlayer.ComponentMiner.ActiveBlockValue;
        int num = Terrain.ExtractContents(activeBlockValue);
        if (m_XFButton.IsClicked)
        {
            if (m_componentPlayer.PlayerData.Level > 1.1f && m_subsystemHL.JC < 1.5f && m_componentPlayer.PlayerData.Level < 28f)
            {
                m_componentPlayer.ComponentGui.DisplaySmallMessage("提升成功！", Color.White, blinking: true, playNotificationSound: false);
                m_subsystemHL.JC += 0.1f;
                m_componentPlayer.PlayerData.Level -= 0.1f;
            }
            else
            {
                m_componentPlayer.ComponentGui.DisplaySmallMessage("提升失败,等级不足或是已达上限，或是超过二阶上级\n当前等级加成:" + JC + "%", Color.White, blinking: true, playNotificationSound: false);
            }
        }
        if (m_XF1Button.IsClicked)
        {
            m_componentPlayer.ComponentGui.DisplayLargeMessage("禁法！", "被闪电击中与随时晕倒的概率提升！\n但是提升等级速度很快", 5f, 0f);
            m_subsystemHL.JC += 0.8f;
        }
        if (m_XF2Button.IsClicked)
        {
            m_componentPlayer.ComponentGui.DisplayLargeMessage("提示:", "可选择法书物品修炼法术\n目前无实际用处", 5f, 0f);
        }
        if (m_XF3Button.IsClicked)
        {
            m_componentPlayer.ComponentGui.DisplayLargeMessage("提示:", "当前剑加成:" + m_subsystemHL.JianJC + "\n" + "修法加成:" + XF, 5f, 0f);
        }
        if (m_XF4Button.IsClicked)
        {
            m_componentPlayer.ComponentGui.DisplayLargeMessage("提示:", "暂未加入", 5f, 0f);
        }
        if (m_XF5Button.IsClicked)
        {
            m_componentPlayer.ComponentGui.DisplayLargeMessage("提示:", "暂未加入", 5f, 0f);
        }
    }
}
